package cn.bytecollege.admin.controller;

import cn.bytecollege.admin.service.CategoryService;
import cn.bytecollege.common.constant.Resource;
import cn.bytecollege.common.entity.Category;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "CategoryFindController", value = "/admin/categoryFind")
public class CategoryFindController extends HttpServlet {
    private CategoryService categoryService=null;
    public CategoryFindController(){
        categoryService=new CategoryService();
    }
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.获取请求参数
        String id=request.getParameter("id");
        Integer categoryId=Integer.valueOf(id);
        //2.封装数据
        Category category=categoryService.findById(categoryId);
        request.setAttribute("category",category);
        //请求转发到修改页面
        request.getRequestDispatcher(Resource.PAGE_LOCATION+"/admin/categoryUpdate.jsp").forward(request,response);

    }
}
